package 力扣日常刷题.木23一月.第07天307;

/**
 * @author 帅小伙
 * @date 2022/3/7
 * @description
 */
public class Demo12超过一半的数字 {

    public int majorityElement(int[] nums) {
        int ans = 0;
        int count = 0;
        for (int num : nums) {
            if(count == 0){
                ans = num;
            }
            if(num == ans){
                count++;
            }else{
                count--;
            }
        }
        return ans;
    }

}
